package com.xuanwu.mall.goods.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * xuanwu-mall
 * com.xuanwu.mall.goods.config
 *
 * @Description:
 * @Author：xuanwudeshuijngye_26567
 * @Date 2024-03-16 16:26
 * @Company: 旋舞科技有限公司
 **/
@Configuration
@ConditionalOnClass(value = {MybatisPlusConfig.class})
public class MybatisPlusConfig {

    /**
     *  新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false
     *  避免缓存出现问题(该属性会在旧插件移除后一同移除)
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        //1、定义mp 拦截器
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        //2、 添加具体的拦截器
        PaginationInnerInterceptor paginationInterceptor=new PaginationInnerInterceptor();
        paginationInterceptor.setDbType(DbType.MYSQL);
        mybatisPlusInterceptor.addInnerInterceptor(paginationInterceptor);
        return mybatisPlusInterceptor;
    }
}

